package xyz.xtt.exchange.service.impl;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.exchange.constants.RocketMessageDelayLevelEnum;
import xyz.xtt.exchange.service.IRocketMqService;

/**
 * @author huqibo
 *
 */
@Slf4j
@Service
public class RocketMqServiceImpl implements IRocketMqService {

	@Autowired
	private RocketMQTemplate rocketMQTemplate;

	@Override
	public void sendDelayedMessage(String topic, String message, RocketMessageDelayLevelEnum delayLevel) {
		SendResult sendResult = rocketMQTemplate.syncSend(topic, MessageBuilder.withPayload(message).build(), 2000, delayLevel.level());
		log.info("sendDelayedMessage topic:{} sendResult:{}", topic, JSONUtil.toJsonStr(sendResult));
	}

}
